package controller

import (
	"gostore/common"
	"gostore/dao/system"
	"gostore/model"
	"gostore/router"

	"github.com/gin-gonic/gin"
)

type AdminControllerT struct {
	BaseControllerT
}

var AdminController = AdminControllerT{}

// @Summary 管理员信息
// @Description  通过account获取对应订单信息，account在登录后由JWT()自动注入
// @Accept json
// @Produce json
// @Success 200 {string} string "{"code"":0,"data":"","msg":"ok"}"
// @Router /api/admin [get]
func (a AdminControllerT) Info(c *gin.Context) {
	account, exists := c.Get("account")
	if exists {
		if str, ok := account.(string); ok {
			admin := model.SystemAdmin{}
			err := system.AdminDao.GetByAccount(&admin, str)
			if err == nil {
				admin.Pwd = ""
				common.Ok(c, admin)
				return
			}
		}
	}
	common.Err(c, 1, "错误的用户名，请重新登录")
}

func (a AdminControllerT) AddNewRoutes() {
	router.AddRouteGroup("/api/admin", []router.Route{
		router.Route{
			Path:    "",
			Method:  router.MGet,
			Handler: a.Info,
		},
	})
}
